<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>食材信息添加</title>
    <%@ include file="include/head.jsp" %>
</head>
<body>
<div class="container-fluid">
    <ul class="nav nav-tabs">
        <li><a href="FoodServlet?action=list">食材信息列表</a></li>
        <li class="active"><a href="#">添加</a></li>
    </ul>
    <br/>
    <form class="form-horizontal" role="form" action="FoodServlet?action=add" method="post" onsubmit="return check()">
        <div class="form-group">
            <label class="col-sm-3 control-label">名称：</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" id="foodName" name="foodName">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">类别：</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" id="foodType" name="foodType">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">评价：</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" id="foodPingjia" name="foodPingjia">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">描述：</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" id="foodMiaosu" name="foodMiaosu">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-5">
                <textarea rows="3" class="form-control" id="foodText" name="foodText" placeholder="请输入内容......"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label"></label>
            <div class="col-sm-5">
                <input type="submit" class="btn btn-rect btn-grad btn-primary btn-sm" value="保存">
                <input type="button" class="btn btn-rect btn-grad btn-warning btn-sm" value="返回" onclick="javascript:history.back(-1);">
            </div>
        </div>
    </form>
</div>
</body>
<script type="text/javascript">
    //提交之前进行检查，如果return false，则不允许提交
    function check() {
        //根据ID获取值
        if (document.getElementById("foodName").value.trim().length == 0) {
            alert("名称不能为空!");
            return false;
        }
        if (document.getElementById("foodType").value.trim().length == 0) {
            alert("类别不能为空!");
            return false;
        }
        if (document.getElementById("foodPingjia").value.trim().length == 0) {
            alert("评价不能为空!");
            return false;
        }
        if (document.getElementById("foodMiaosu").value.trim().length == 0) {
            alert("描述不能为空!");
            return false;
        }
        return true;
    }
</script>
</html>
